﻿@{
    Layout = "~/_SiteLayout.cshtml";
    
    Business.Platform.Organize borganize = new Business.Platform.Organize();
    Data.Model.Organize org = null;
    string id = Request.QueryString["id"];
    
    string name = string.Empty;
    string type = string.Empty;
    string status = string.Empty;
    string note = string.Empty;

    Guid orgID;
    if (id.IsGuid(out orgID))
    {
        org = borganize.Get(orgID);
    }
    
    Validation.RequireFields("Name", "Type", "Status");
    if (IsPost && Validation.IsValid() && org!=null)
    {
        name = Request.Form["Name"];
        type = Request.Form["Type"];
        status = Request.Form["Status"];
        note = Request.Form["note"];
        
        Data.Model.Organize org1 = new Data.Model.Organize();
        Guid org1ID = Guid.NewGuid();
        org1.ID = org1ID;
        org1.Name = name.Trim();
        org1.Note = note.IsNullOrEmpty() ? null : note.Trim();
        org1.Number = org.Number + "," + org1ID.ToString().ToLower();
        org1.ParentID = org.ID;
        org1.Sort = borganize.GetMaxSort(org.ID);
        org1.Status = status.IsInt() ? status.ToInt() : 0;
        org1.Type = type.ToInt();
        org1.Depth = org.Depth + 1;

        using (System.Transactions.TransactionScope scope = new System.Transactions.TransactionScope())
        {
            borganize.Add(org1);
            //更新父级[ChildsLength]字段
            borganize.UpdateChildsLength(org.ID);
            scope.Complete();
        }

        Business.Platform.Log.Add("添加了组织机构", org1.Serialize(), Business.Platform.Log.Types.组织机构);
        
        <script type="text/javascript">
            parent.frames[0].reLoad('@id');
            alert('添加成功!');
            window.location=window.location;
        </script>
        
    }
    
    string typeRadios = borganize.GetTypeRadio("Type", type, "validate=\"radio\"");
    string statusRadios = borganize.GetStatusRadio("Status", "0", "validate=\"radio\"");
    }
    <script type="text/javascript">
        var win = new RoadUI.Window();
        var validate = new RoadUI.Validate();
    </script>
    <form action="" method="post">
    <br />
    <table cellpadding="0" cellspacing="1" border="0" width="95%" class="formtable">
        <tr>
            <th style="width:80px;">名称：</th>
            <td><input type="text" id="Name" name="Name" class="mytext" validate="empty,minmax" value="@name" max="100" style="width:75%" /></td>
        </tr>
        <tr>
            <th style="width:80px;">类型：</th>
            <td>@Html.Raw(typeRadios)</td>
        </tr>
        <tr>
            <th style="width:80px;">状态：</th>
            <td>@Html.Raw(statusRadios)</td>
        </tr>
        <tr>
            <th style="width:80px;">备注：</th>
            <td><textarea id="Note" name="Note" class="mytext" style="width:90%; height:50px;">@note</textarea></td>
        </tr>

        <tr id="deptmove_tr" style="display:none;">
            <th style="width:80px;">移动到：</th>
            <td>
                <table cellpadding="0" cellspacing="0" border="0">
                    <tr>
                        <td><input type="text" style="width:220px;" class="mymember" id="deptmove" more="false" user="false" station="true" dept="true" unit="true"/></td>
                        <td><input type="submit" class="mybutton" name="Move" value="确定移动" /></td>
                    </tr>
                </table>
            </td>
        </tr>

    </table>
    <div style="width:95%; margin:10px auto 10px auto; text-align:center;">
        <input type="submit" class="mybutton" onclick="return validate.validateForm(document.forms[0]);" name="Save" value="保存" />
        <input type="button" class="mybutton" value="返回" onclick="window.location='Body'+'@Request.Url.Query';" />
    </div>
    </form>